package com.xuelang.pipeline.entry.pipeline;

import com.xuelang.pipeline.app.pipeline.PipelineTemplateService;
import com.xuelang.pipeline.client.common.request.PageParam;
import com.xuelang.pipeline.client.common.result.ApiResult;
import com.xuelang.pipeline.client.common.result.PageRecord;
import com.xuelang.pipeline.client.pipeline.IPipelineTemplateService;
import com.xuelang.pipeline.client.pipeline.dto.PipelineTemplateConfigDTO;
import com.xuelang.pipeline.client.pipeline.dto.PipelineTemplateCopyDTO;
import com.xuelang.pipeline.client.pipeline.dto.PipelineTemplateDTO;
import com.xuelang.pipeline.client.pipeline.dto.PipelineTemplateQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 流水线模板服务web控制类
 *
 * @author xiwen.zxg
 * @since 2024/5/22
 */
@Slf4j
@RestController
@RequestMapping("/pipeline-template")
public class PipelineTemplateController implements IPipelineTemplateService {

    @Autowired
    private PipelineTemplateService pipelineTemplateService;

    @Override
    public ApiResult<PageRecord<PipelineTemplateDTO>> pagePipelineTemplateList(PageParam<PipelineTemplateQuery> dtoPageParam) {
        return ApiResult.success(pipelineTemplateService.pageList(dtoPageParam));
    }

    @Override
    public ApiResult<List<PipelineTemplateDTO>> conditionalPipelineTemplateList(PipelineTemplateQuery pipelineTemplateQuery) {
        return ApiResult.success(pipelineTemplateService.list(pipelineTemplateQuery));
    }

    @Override
    public ApiResult<Boolean> addPipelineTemplate(PipelineTemplateConfigDTO pipelineTemplateConfigDTO) {
        return ApiResult.success(pipelineTemplateService.add(pipelineTemplateConfigDTO));
    }

    @Override
    public ApiResult<Boolean> updatePipelineTemplate(PipelineTemplateConfigDTO pipelineTemplateConfigDTO) {
        return ApiResult.success(pipelineTemplateService.update(pipelineTemplateConfigDTO));
    }

    @Override
    public ApiResult<Boolean> deletePipelineTemplate(String pipelineTemplateUuid) {
        return ApiResult.success(pipelineTemplateService.delete(pipelineTemplateUuid));
    }

    @Override
    public ApiResult<PipelineTemplateDTO> queryPipelineTemplate(String pipelineTemplateUuid) {
        return ApiResult.success(pipelineTemplateService.query(pipelineTemplateUuid));
    }

    @Override
    public ApiResult<PipelineTemplateConfigDTO> queryPipelineTemplateConfig(String pipelineTemplateUuid) {
        return ApiResult.success(pipelineTemplateService.pipelineTemplateConfig(pipelineTemplateUuid));
    }

    @Override
    public ApiResult<Boolean> copyPipelineTemplate(PipelineTemplateCopyDTO pipelineTemplateCopyDTO) {
        String pipelineTemplateUuid = pipelineTemplateCopyDTO.getPipelineTemplateUuid();
        String newPipelineTemplateName = pipelineTemplateCopyDTO.getNewPipelineTemplateName();
        return ApiResult.success(pipelineTemplateService.copyPipelineTemplate(pipelineTemplateUuid, newPipelineTemplateName));
    }

}
